import type { DataTableColumns } from 'naive-ui'
import type { CreateColumsOptions } from '@/types/fcform'

export const createColums = ({ handDel, action }: CreateColumsOptions): DataTableColumns => {
  return [
    {
      type: 'selection',
      options: ['all', 'none'],
    },
    {
      title: '序号',
      key: 'key',
      width: 70,
      render: (_, index) => {
        return `${index + 1}`
      },
    },
    {
      title: '岗位编号',
      key: 'postCode',
    },
    {
      title: '岗位名称',
      key: 'postName',
    },
    {
      title: '岗位排序',
      key: 'postSort',
    },
    {
      title: '岗位描述',
      key: 'remark',
    },
    {
      title: '操作',
      key: 'total',
      align: 'center',
      width: 120,
      render(row) {
        const arr = []
        if (commonUnit.auth('sys_post_edit')) {
          const editBtn = fastUnit.createBtn('编辑', {
            type: 'warning',
            onClick: () => action.default(row),
          })
          arr.push(editBtn)
        }
        if (commonUnit.auth('sys_post_del')) {
          const delBtn = fastUnit.createBtn('删除', {
            type: 'error',
            disabled: row.roleCode === 'ROLE_ADMIN',
            onClick: () => handDel(row),
          })
          arr.push(delBtn)
        }
        return h('div', arr)
      },
    },
  ]
}
